package com.yanqu.road.dao.impl.activity.specialcookboy;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.specialcookboy.config.*;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SpecialCookBoyConfigDaoImpl extends TempDao {
    private static String getSpecialCookBoyLevelConfigSql = "select * from `t_s_chinesechef_activity_level` where `activityId`=? ORDER BY `levelId` ASC";
    public Map<Integer,SpecialCookBoyLevelConfig> getSpecialCookBoyLevelConfigList(int activityId) {
        Map<Integer,SpecialCookBoyLevelConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getSpecialCookBoyLevelConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SpecialCookBoyLevelConfig specialCookBoyLevelConfig = new SpecialCookBoyLevelConfig();
                specialCookBoyLevelConfig.setActivityId(rs.getInt("activityId"));
                specialCookBoyLevelConfig.setLevelId(rs.getInt("levelId"));
                specialCookBoyLevelConfig.setLevelOrder(rs.getInt("levelOrder"));
                specialCookBoyLevelConfig.setType(rs.getInt("type"));
                specialCookBoyLevelConfig.setName(rs.getString("name"));
                specialCookBoyLevelConfig.setDesc(rs.getString("desc"));
                specialCookBoyLevelConfig.setOnceReward(rs.getString("onceReward"));
                specialCookBoyLevelConfig.setUnlock(rs.getInt("unlock"));
                specialCookBoyLevelConfig.setTimeLimit(rs.getInt("timeLimit"));
                specialCookBoyLevelConfig.setInitialValue(rs.getInt("initialValue"));
                specialCookBoyLevelConfig.setTargetValue(rs.getInt("targetValue"));
                map.put(specialCookBoyLevelConfig.getLevelId(),specialCookBoyLevelConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    private static String getSpecialCookBoyItemConfigSql = "select * from `t_s_chinesechef_activity_item` where `activityId`=? ORDER BY `levelId` ASC";
    public List<SpecialCookBoyItemConfig> getSpecialCookBoyItemConfigList(int activityId) {
        List<SpecialCookBoyItemConfig> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getSpecialCookBoyItemConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SpecialCookBoyItemConfig specialCookBoyItemConfig = new SpecialCookBoyItemConfig();
                specialCookBoyItemConfig.setActivityId(rs.getInt("activityId"));
                specialCookBoyItemConfig.setLevelId(rs.getInt("levelId"));
                specialCookBoyItemConfig.setItemsort(rs.getInt("itemsort"));
                specialCookBoyItemConfig.setName(rs.getString("name"));
                specialCookBoyItemConfig.setItemInteractiveType(rs.getInt("itemInteractiveType"));
                specialCookBoyItemConfig.setIsSpine(rs.getInt("isSpine"));
                list.add(specialCookBoyItemConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    private static String getSpecialCookBoyEventConfigSql = "select * from `t_s_chinesechef_activity_events` where `activityId`=? ORDER BY `levelId` ASC";
    public List<SpecialCookBoyEventConfig> getSpecialCookBoyEventConfigList(int activityId) {
        List<SpecialCookBoyEventConfig> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getSpecialCookBoyEventConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SpecialCookBoyEventConfig specialCookBoyEventConfig = new SpecialCookBoyEventConfig();
                specialCookBoyEventConfig.setActivityId(rs.getInt("activityId"));
                specialCookBoyEventConfig.setLevelId(rs.getInt("levelId"));
                specialCookBoyEventConfig.setEventSort(rs.getInt("eventSort"));
                specialCookBoyEventConfig.setInteractiveOne(rs.getInt("interactiveOne"));
                specialCookBoyEventConfig.setInteractiveTwo(rs.getInt("interactiveTwo"));
                specialCookBoyEventConfig.setInteractiveTextDesc(rs.getString("interactiveTextDesc"));
                specialCookBoyEventConfig.setBubbleItem(rs.getInt("bubbleItem"));
                specialCookBoyEventConfig.setBubbleOffset(rs.getString("bubbleOffset"));
                specialCookBoyEventConfig.setWeight(rs.getInt("weight"));
                specialCookBoyEventConfig.setPredecessors(rs.getString("predecessors"));
                specialCookBoyEventConfig.setFailPredecessorsDesc(rs.getString("failPredecessorsDesc"));
                list.add(specialCookBoyEventConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    private static String getSpecialCookBoyPromptConfigSql = "select * from `t_s_chinesechef_activity_prompt` where `activityId`=? ORDER BY `levelId` ASC";
    public Map<Integer,SpecialCookBoyPromptConfig> getSpecialCookBoyPromptConfigMap(int activityId) {
        Map<Integer,SpecialCookBoyPromptConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getSpecialCookBoyPromptConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SpecialCookBoyPromptConfig specialCookBoyPromptConfig = new SpecialCookBoyPromptConfig();
                specialCookBoyPromptConfig.setActivityId(rs.getInt("activityId"));
                specialCookBoyPromptConfig.setLevelId(rs.getInt("levelId"));
                specialCookBoyPromptConfig.setPromptSort(rs.getInt("promptSort"));
                specialCookBoyPromptConfig.setPromptName(rs.getString("promptName"));
                specialCookBoyPromptConfig.setRecordId(rs.getInt("recordId"));
                map.put(specialCookBoyPromptConfig.getRecordId(),specialCookBoyPromptConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    private static String getSpecialCookBoyChoosePassRoadEventConfigSql = "select * from `t_s_chinesechef_activity_choose` where `activityId`=? ORDER BY `eventId` ASC";
    public Map<Integer,SpecialCookBoyChoosePassRoadEventConfig> getSpecialCookBoyChoosePassRoadEventConfigMap(int activityId) {
        Map<Integer,SpecialCookBoyChoosePassRoadEventConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getSpecialCookBoyChoosePassRoadEventConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SpecialCookBoyChoosePassRoadEventConfig specialCookBoyChoosePassRoadEventConfig = new SpecialCookBoyChoosePassRoadEventConfig();
                specialCookBoyChoosePassRoadEventConfig.setActivityId(rs.getInt("activityId"));
                specialCookBoyChoosePassRoadEventConfig.setEventId(rs.getInt("eventId"));
                specialCookBoyChoosePassRoadEventConfig.setType(rs.getInt("type"));
                specialCookBoyChoosePassRoadEventConfig.setName(rs.getString("name"));
                specialCookBoyChoosePassRoadEventConfig.setDesc(rs.getString("desc"));
                specialCookBoyChoosePassRoadEventConfig.setReward(rs.getString("reward"));
                specialCookBoyChoosePassRoadEventConfig.setParLists(rs.getString("parLists"));
                map.put(specialCookBoyChoosePassRoadEventConfig.getEventId(),specialCookBoyChoosePassRoadEventConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    private static String getSpecialCookBoyTipConfigSql = "select * from `t_s_chinesechef_activity_tip` where `activityId`=? ORDER BY `tipId` ASC";
    public List<SpecialCookBoyTipConfig> getSpecialCookBoyTipConfigList(int activityId) {
        List<SpecialCookBoyTipConfig> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getSpecialCookBoyTipConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SpecialCookBoyTipConfig specialCookBoyTipConfig = new SpecialCookBoyTipConfig();
                specialCookBoyTipConfig.setActivityId(rs.getInt("activityId"));
                specialCookBoyTipConfig.setLevelId(rs.getInt("levelId"));
                specialCookBoyTipConfig.setTipId(rs.getInt("tipId"));
                specialCookBoyTipConfig.setHeadPortraitId(rs.getString("headPortraitId"));
                specialCookBoyTipConfig.setTaskCompleted(rs.getString("taskCompleted"));
                specialCookBoyTipConfig.setTipDesc(rs.getString("tipDesc"));
                specialCookBoyTipConfig.setTipCoordinate(rs.getString("tipCoordinate"));
                specialCookBoyTipConfig.setTipTime(rs.getInt("tipTime"));
                list.add(specialCookBoyTipConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    private static String getSpecialCookBoyGuideConfigSql = "select * from `t_s_chinesechef_activity_guide` where `activityId`=? ORDER BY `levelId` ASC";
    public List<SpecialCookBoyGuideConfig> getSpecialCookBoyGuideConfigList(int activityId) {
        List<SpecialCookBoyGuideConfig> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getSpecialCookBoyGuideConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SpecialCookBoyGuideConfig specialCookBoyGuideConfig = new SpecialCookBoyGuideConfig();
                specialCookBoyGuideConfig.setActivityId(rs.getInt("activityId"));
                specialCookBoyGuideConfig.setLevelId(rs.getInt("levelId"));
                specialCookBoyGuideConfig.setGuideType(rs.getInt("guideType"));
                specialCookBoyGuideConfig.setGuideId(rs.getInt("guideId"));
                specialCookBoyGuideConfig.setGuideDesc(rs.getString("guideDesc"));
                specialCookBoyGuideConfig.setCharacterId(rs.getInt("characterId"));
                specialCookBoyGuideConfig.setCharacterName(rs.getString("characterName"));
                list.add(specialCookBoyGuideConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }






}
